package com.tianaceae.educational.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.tianaceae.educational.domain.EduSubject;
import com.tianaceae.educational.service.IEduSubjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教务科目Controller
 * 
 * @author zhouhonggang
 * @date 2023-03-28
 */
@RestController
@RequestMapping("/subject/subject")
public class EduSubjectController extends BaseController
{
    @Autowired
    private IEduSubjectService eduSubjectService;

    /**
     * 查询教务科目列表
     */
    @PreAuthorize("@ss.hasPermi('subject:subject:list')")
    @GetMapping("/all")
    public TableDataInfo all(EduSubject eduSubject)
    {
        List<EduSubject> list = eduSubjectService.selectEduSubjectList(eduSubject);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('subject:subject:list')")
    @GetMapping("/list")
    public TableDataInfo list(EduSubject eduSubject)
    {
        startPage();
        List<EduSubject> list = eduSubjectService.selectEduSubjectList(eduSubject);
        return getDataTable(list);
    }

    /**
     * 导出教务科目列表
     */
    @PreAuthorize("@ss.hasPermi('subject:subject:export')")
    @Log(title = "教务科目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EduSubject eduSubject)
    {
        List<EduSubject> list = eduSubjectService.selectEduSubjectList(eduSubject);
        ExcelUtil<EduSubject> util = new ExcelUtil<EduSubject>(EduSubject.class);
        util.exportExcel(response, list, "教务科目数据");
    }

    /**
     * 获取教务科目详细信息
     */
    @PreAuthorize("@ss.hasPermi('subject:subject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(eduSubjectService.selectEduSubjectById(id));
    }

    /**
     * 新增教务科目
     */
    @PreAuthorize("@ss.hasPermi('subject:subject:add')")
    @Log(title = "教务科目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EduSubject eduSubject)
    {
        return toAjax(eduSubjectService.insertEduSubject(eduSubject));
    }

    /**
     * 修改教务科目
     */
    @PreAuthorize("@ss.hasPermi('subject:subject:edit')")
    @Log(title = "教务科目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EduSubject eduSubject)
    {
        return toAjax(eduSubjectService.updateEduSubject(eduSubject));
    }

    /**
     * 删除教务科目
     */
    @PreAuthorize("@ss.hasPermi('subject:subject:remove')")
    @Log(title = "教务科目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eduSubjectService.deleteEduSubjectByIds(ids));
    }

    @Log(title = "教务科目", businessType = BusinessType.OTHER)
    @GetMapping("/{id1}/{id2}/{direction}")
    public AjaxResult direction(
        @PathVariable int id1,
        @PathVariable int id2,
        @PathVariable int direction
    ) {
        return toAjax(eduSubjectService.updateEduSubjectDirection(id1, id2, direction));
    }

}
